using System;
using System.Collections.Generic;
using System.Text;

namespace ClientTools.Library.DocumentTypes
{
    public class DocumentType
    {
        public DocumentType() { }
        public DocumentType(umbraco.cms.businesslogic.web.DocumentType umbracoDocumentType) 
        {
            this._alias = umbracoDocumentType.Alias;    
            this._name = umbracoDocumentType.Text;
            this._thumbnail = umbracoDocumentType.Thumbnail;
            this._icon = umbracoDocumentType.IconUrl;
            //this._defaultTemplate = new umbraco.cms.businesslogic.template.Template(umbracoDocumentType.DefaultTemplate).Alias;
            foreach (umbraco.cms.businesslogic.template.Template umbracoTemplate in umbracoDocumentType.allowedTemplates)
            {
                this._templates.Add(umbracoTemplate.Alias);
            }
            foreach (int umbracoChildId in umbracoDocumentType.AllowedChildContentTypeIDs)
            {
                this._allowedChilds.Add(new umbraco.cms.businesslogic.web.DocumentType(umbracoChildId).Alias);
            }
            foreach (umbraco.cms.businesslogic.ContentType.TabI umbracoTab in umbracoDocumentType.getVirtualTabs)
            {
                Tab tab = new Tab();
                tab.Caption = umbracoTab.Caption;
                tab.Id = umbracoTab.Id;
                this._tabs.Add(tab);
            }
            foreach (umbraco.cms.businesslogic.propertytype.PropertyType umbracoPropertyType in umbracoDocumentType.PropertyTypes)
            {
                GenericProperty genProp = new GenericProperty();
                genProp.Alias = umbracoPropertyType.Alias;
                genProp.Description = umbracoPropertyType.Description;
                genProp.Mandatory = umbracoPropertyType.Mandatory;
                genProp.Name = umbracoPropertyType.Name;
                foreach (umbraco.cms.businesslogic.ContentType.TabI tab in umbracoDocumentType.getVirtualTabs)
                {
                    if (tab.Id == umbracoPropertyType.TabId)
                    {
                        genProp.Tab = tab.Caption;
                        break;
                    }
                }
                genProp.Type = umbracoPropertyType.DataTypeDefinition.Text;
                genProp.Validation = umbracoPropertyType.ValidationRegExp;
                this._genericProperties.Add(genProp);
            }
        }

        private GenericPropertyCollection _genericProperties = new GenericPropertyCollection();
        public GenericPropertyCollection GenericProperties
        {
            get { return _genericProperties; }
            set { _genericProperties = value; }
        }

        private TabCollection _tabs = new TabCollection();
        public TabCollection Tabs
        {
            get { return _tabs; }
            set { _tabs = value; }
        }

        private List<string> _allowedChilds = new List<string>();
        public List<string> AllowedChilds
        {
            get { return _allowedChilds; }
            set { _allowedChilds = value; }
        }

        private List<string> _templates = new List<string>();
        public List<string> Templates
        {
            get { return _templates; }
            set { _templates = value; }
        }

        private string _defaultTemplate;
        public string DefaultTemplate
        {
            get { return _defaultTemplate; }
            set { _defaultTemplate = value; }
        }
	
        private string _icon;
        public string Icon
        {
            get { return _icon; }
            set { _icon = value; }
        }
	
        private string _thumbnail;
        public string Thumbnail
        {
            get { return _thumbnail; }
            set { _thumbnail = value; }
        }

        private string _alias;
        public string Alias
        {
            get { return _alias; }
            set { _alias = value; }
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
    }
}
